package com.liwenfeng.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

//用正则表达式匹配电话号码，邮箱，座机号码
//爬虫爬取数据
public class RegexDemo {
    public static void main(String[] args) {
        String rs = "来黑马程序学习，电话020-43422424，或联系邮箱itcast@itcast.cn,电话：18762832633,02032322323 邮箱：bozai@itcast.cn,400-100-3233,4001003232";
        String regex = "(\\w{1,}@\\w{2,10}(\\.\\w{2,10}){1,2})|(1[3-9]\\d{9})|(0\\d{2,5}-?\\d{5,15})|400-?\\d{3,8}-?\\d{3,8}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(rs);
        while (matcher.find()){
            System.out.println(matcher.group());
        }
    }
/**输出结果：
020-43422424
itcast@itcast.cn
18762832633
02032322323
bozai@itcast.cn
400-100-3233
4001003232
**/
}
